package com.xii.eduservice.controller;


import com.xii.commonutils.R;
import com.xii.eduservice.entity.subject.OneSubject;
import com.xii.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author xhjava
 * @since 2022-02-10
 */
@RestController
@RequestMapping("/eduservice/subject")
@Api(description = "课程分类管理")
//@CrossOrigin  //跨域
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //添加课程
     //获取上传过来的文件 把文件内容读取出来
    @PostMapping("addSubject")
    @ApiOperation(value = "上传课程分类文件")
    public R addSubject(MultipartFile file){   //MultipartFile 获取文件
        //上传过来的文件
        subjectService.saveSubject(file,subjectService);
        return R.ok();
    }


    @GetMapping("getAllSubject")
    @ApiOperation(value = "得到课程分类列表（树形菜单）")
    public R getAllSubject(){
        //list集合泛型 是一级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

